/**
 * @author 雷明浩
 * @date 2025/7/18 15:45
 */
public class Solve {
    // 验证IP地址
    // https://www.nowcoder.com/practice/55fb3c68d08d46119f76ae2df7566880?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295
    public String solve (String IP) {
        // write code here
        if (IP.startsWith("\\.") || IP.endsWith("\\.")
                || IP.startsWith(":") || IP.endsWith(":")) {
            return "Neither";
        }
        String[] ips = IP.split("\\.");
        if (ips.length == 4) {
            // ipv4
            for (String s : ips) {
                try {
                    int num = Integer.parseInt(s);
                    if ((s.length() > 1 && s.charAt(0) == '0')
                            || num < 0 || num > 255) {
                        return "Neither";
                    }
                } catch (Exception e) {
                    return "Neither";
                }
            }
            return "IPv4";
        } else {
            String[] ipv6 = IP.split(":");
            if (ipv6.length != 8) {
                return "Neither";
            }
            for (String s : ipv6) {
                if (s.length() == 0) {
                    return "Neither";
                }
                String ss = s.toUpperCase();
                boolean flg = false;
                for (char c : ss.toCharArray()) {
                    if (c != '0') {
                        flg = true;
                    }
                    if (!Character.isDigit(c) && (c > 'F')) {
                        return "Neither";
                    }
                }
                if (!flg && ss.length() > 1) {
                    return "Neither";
                }
            }
            return "IPv6";
        }
    }

    public static void main(String[] args) {
        Solve solve = new Solve();
        System.out.println(solve.solve("2001:0db8:85a3:0:0:8A2E:0370:7334:"));
    }
}